package com.csaba.swing.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import com.csaba.swing.MainWindow;
import com.csaba.swing.gui.ChangePasswordDialog;
import com.csaba.swing.gui.util.GUIUtil;
import com.csaba.util.encryption.EncryptedStore;
import com.csaba.util.encryption.EncryptedStoreEvent;
import com.csaba.util.encryption.EncryptedStoreListener;

@SuppressWarnings( "serial" )
public class ChangePasswordAction extends AbstractAction implements EncryptedStoreListener
{
	public ChangePasswordAction()
	{
		super(MainWindow.getString("ChangePasswordAction.menuItem")); //$NON-NLS-1$
		EncryptedStore.getInstance().addEncryptedStoreListener(this);
		setEnabled(EncryptedStore.getInstance().isOpen());
		//set icon

		GUIUtil.setMnemonic(this);
	}

	@Override
	public void actionPerformed( final ActionEvent e )
	{
		final ChangePasswordDialog dialog = new ChangePasswordDialog(MainWindow.getFrame());
		dialog.setVisible(true);
	}

	@Override
	public void storeUpdated( final EncryptedStoreEvent event )
	{
		if ( event.getEventType() == EncryptedStoreEvent.STORE_OPEN )
			setEnabled(true);

	}
}
